Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Simple flag in annotated assignment #245

Merged
merged 6 commits into from
Jun 27, 2024

Conversation

dwoznicki
Copy link
Collaborator

@dwoznicki dwoznicki commented Jun 25, 2024

I'm a bit medium about this solution. It avoids a lookup for parenthesis tokens inside parse_ann_assign_statement at the cost of an extra field on the Name expression. I'm not sure if this is a reasonable trade-off.

Failing tests are expected for the time being.

Related: #127

@Glyphack
Copy link
Owner

Glyphack commented Jun 25, 2024

Thanks, I would take a look when I'm home. I'd also try to see what https://github.com/astral-sh/ruff does in their parser to detect the "()" on the names. But I do think your other idea with checking the source code using offset worth giving a try too.

By the way for tests you can use https://insta.rs/docs/cli/ to update them.

Copy link

codspeed-hq bot commented Jun 25, 2024

CodSpeed Performance Report

Merging #245 will not alter performance

Comparing dwoznicki:simple-flag-annotated-assignment (398c573) with main (d6dc09e)

Summary

✅ 4 untouched benchmarks

Copy link
Owner

@Glyphack Glyphack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the change is good. Please add cases to cover this in the snapshots and also update the old snapshots.

Regarding checking the source. I think there are more cases to cover like:

(
a
) = 1

Where the ( is not exactly the character before the name. So that might introduce more complexity.

@dwoznicki
Copy link
Collaborator Author

dwoznicki commented Jun 26, 2024

Okay, I added some tests. I can't help but feel like this is too much overhead for such a niche use case. Perhaps this should be a new expression type, ParenthesizedName? How closely are you trying to follow the standard Python AST node types?

@Glyphack
Copy link
Owner

Glyphack commented Jun 26, 2024

Okay, I added some tests. I can't help but feel like this is too much overhead for such a niche use case. Perhaps this should be a new expression type, ParenthesizedName? How closely are you trying to follow the standard Python AST node types?

I think this extra field is better than a new node type. Since that new node type has to be handled in type checker when getting type for an expression and might complicate more stuff.

With current approach we can leave the detail inside the parser. I think we can even override fmt debug for the Name to hide this attribute in the debug value so it won't show up in the tests as a change.
https://doc.rust-lang.org/std/fmt/trait.Debug.html#examples

@dwoznicki
Copy link
Collaborator Author

Cool, I like that idea. Tests should be good to go. Looks like codecov is getting (badly) throttled.

[2024-06-27T06:04:24.041Z] ['error'] There was an error running the uploader: Error uploading to [https://codecov.io:](https://codecov.io/) Error: There was an error fetching the storage URL during POST: 429 - {'detail': ErrorDetail(string='Rate limit reached. Please upload with the Codecov repository upload token to resolve issue. Expected time to availability: 2947s.', code='throttled')}

Copy link
Owner

@Glyphack Glyphack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@Glyphack Glyphack merged commit bdf96b2 into Glyphack:main Jun 27, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants